#include "titlewg.h"
#include "ui_titlewg.h"
#include <QMouseEvent>

TitleWg::TitleWg(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TitleWg)
{
    ui->setupUi(this);

    ui->logo->setPixmap(QPixmap(":/images/logo.png").scaled(40, 40));

    m_parent = parent;

    connect(ui->set, &QToolButton::clicked, this, [=]()
    {
        emit showSetwg();
    });

    connect(ui->min, &QToolButton::clicked, this, [=]()
    {
        m_parent->showMinimized();
    });

    connect(ui->close, &QToolButton::clicked, this, [=]()
    {
        emit closeWindow();
    });
}

TitleWg::~TitleWg()
{
    delete ui;
}

void TitleWg::mouseMoveEvent(QMouseEvent *event)
{
    if(event->buttons() & Qt::LeftButton)
    {
        m_parent->move(event->globalPos() - m_pt);
    }
}

void TitleWg::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        m_pt = event->globalPos() - m_parent->geometry().topLeft();
    }
}
